package com.yzh.design.demo;

import java.util.concurrent.atomic.AtomicReference;

public class Singleton_06 {
    private volatile static Singleton_06 uniqueInstance;
    private static AtomicReference<Singleton_06> INSTANCE = new AtomicReference<>();
    private static Singleton_06 instance;

    private Singleton_06() {
    }

    public static Singleton_06 getInstance() {
        while (true) {
            instance = INSTANCE.get();
            if (instance != null) return instance;
            INSTANCE.compareAndSet(null, new Singleton_06());
            return INSTANCE.get();
        }
    }
}